﻿@model IEnumerable<KRM.Core.EspressoLogin>
@{
    ViewBag.Title = "Espresso Audit Login";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var page = 1;

    if (Request.QueryString["p"] != null)
    {
        page = Convert.ToInt32(Request.QueryString["p"]);

    }
    var itemPerPage = 30;
    var pagingCount = Convert.ToInt32(Math.Ceiling((Model.Count() / (float)itemPerPage)));
    var listPaging = Model.Skip((page - 1) * itemPerPage).Take(itemPerPage);
}
<script src="/js/tabletocsv.js"></script>
<div class="container-fluid">
    <div class="page-header"></div>
    <form action="/logs/espressologin" method="get" class="margin0">
        <div class="row-fluid">
            <div class="span3">
                <div class="input-append datetimepicker">
                    <input data-format="dd/MM/yyyy" type="text" name="from" placeholder="From" value="@(Request["from"] ?? DateTime.Now.ToString("dd/MM/yyyy"))" style="width: 100%">
                    <span class="add-on">
                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                    </span>
                </div>
            </div>
            <div class="span3">
                <div class="input-append datetimepicker">
                    <input data-format="dd/MM/yyyy" type="text" name="to" placeholder="To" value="@(Request["to"] ?? DateTime.Now.ToString("dd/MM/yyyy"))" style="width: 100%">
                    <span class="add-on">
                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                    </span>
                </div>
            </div>
            <div class="span4">
                <input type="submit" class="btn btn-primary" value="Search" />
                <a href="/logs/espressologin" class="btn btn-danger">Remove Filter</a>
                <button class="btn btn-info" type="button" onclick="ExportCSVWithHead($('.tbody'), 'Table.csv', $('.thead'))">
                    <img src="/img/icon-exel.png" style="max-height: 20px">
                    Export</button>
            </div>
        </div>
    </form>
    <div class="row-fluid">
        <table class="table table-hover table-bordered table-fix">
            <thead class="thead">
                <tr>
                    <th style="text-align: center">ID</th>
                    <th style="text-align: center">UserLogin</th>
                    <th style="text-align: center">Date Login</th>
                    <th style="text-align: center">IP Address</th>
                    <th style="text-align: center">Country</th>
                    <th style="text-align: center">City</th>
                    <th style="text-align: center">Region</th>
                    <th style="text-align: center">Country Code</th>
                    <th style="text-align: center">Latitude</th>
                    <th style="text-align: center">Longitude</th>
                    <th style="text-align: center">ZipCode</th>
                </tr>
            </thead>
            <tbody class="tbody">
                @foreach (var item in listPaging)
                {
                    <tr>
                        <td style="text-align: center">@item.Id</td>
                        <td style="text-align: center">@item.User</td>
                        <td style="text-align: center">@string.Format("{0:hh:mm, dd/MM/yyyy}", item.DateLogin)</td>
                        <td style="text-align: center">@item.IPAddress</td>
                        <td style="text-align: center">@item.CountryName</td>
                        <td style="text-align: center">@item.CityName</td>
                        <td style="text-align: center">@item.RegionName</td>
                        <td style="text-align: center">@item.CountryCode</td>
                        <td style="text-align: center">@item.Latitude</td>
                        <td style="text-align: center">@item.Longitude</td>
                        <td style="text-align: center">@item.ZipCode</td>
                    </tr>
                }
            </tbody>
        </table>
        <div class="paging">
            <a href="/logs/espressologin">«</a>
            <span>
                @for (int j = page - 3; j <= page + 3; j++)
                {
                    if (j > 0 && j <= pagingCount)
                    {
                        if (j == page)
                        {
                    <a href="/logs/espressologin?p=@j" class="page-active">@j</a>
                        }
                        else
                        {
                    <a href="/logs/espressologin?p=@j">@j</a>
                        }

                    }
                }
            </span>
            <a href="/logs/espressologin?p=@pagingCount">»</a>
        </div>
    </div>
</div>
